<?php
/**
 * 活动管理
 * @copyright (c) Seer All Rights Reserved
 */

require_once 'globals.php';

$Activity_Model = new Activity_Model();
$action =$_POST["action"];

//活动添加初期化
if ($action == '') {
	$pwd = '活动添加';
	 include View::getView('header');
	 require_once View::getView('activity_update');
	 include View::getView('footer');View::output();
}

// 活动添加提交
if ($action == 'addcommit') {
	$pwd = '活动添加成功';
	move_uploaded_file($_FILES["activity_cover"]["tmp_name"],
		"upload/" . $_FILES["activity_cover"]["name"]);
	$activity_ID=$Activity_Model->addActivity($_POST["activity_name"],$_POST["activity_deadline"],"upload/" . $_FILES["activity_cover"]["name"]);
	echo $activity_ID;
	include View::getView('header');
	require_once View::getView('activity_update_success');
	include View::getView('footer');View::output();
}

//活动编辑初期化
if ($action == 'update') {

	$activity_ID = isset($_POST['activity_ID']) ? $_POST['activity_ID'] : '';

	$sqlSegment .= ' ORDER BY buildtime DESC ';

	$pwd = '活动编辑';

	$addUrl = $activity_name ? "activity_name={$activity_name}&" : '';

	$activitiesNum = $Activity_Model->getActivitiesNum($activity_name);
	$activies = $Activity_Model->getActivitiesForAdmin($page, $activity_name);
	$pageurl =  pagination($activitiesNum, Option::get('admin_perpage_num'), $page, "activity.php?{$addUrl}pid=");

	include View::getView('header');
	require_once View::getView('activity_update');
	include View::getView('footer');View::output();
}
//活动编辑提交
if ($action == 'update') {
	$activity_ID = isset($_POST['activity_ID']) ? $_POST['activity_ID'] : '';
	$sqlSegment .= ' ORDER BY buildtime DESC ';
	$pwd = '活动管理成功';
	$addUrl = $activity_name ? "activity_name={$activity_name}&" : '';
	$activitiesNum = $Activity_Model->getActivitiesNum($activity_name);
	$activies = $Activity_Model->getActivitiesForAdmin($page, $activity_name);
	$pageurl =  pagination($activitiesNum, Option::get('admin_perpage_num'), $page, "activity.php?{$addUrl}pid=");
	include View::getView('header');
	require_once View::getView('activity_update');
	include View::getView('footer');View::output();
}
